import fitz

# 打开PDF文件
pdf_document = r"D:\PycharmProjects\python_learning_record\national_computer_rank_examination\文件格式转换\机床通讯网关_通讯协议_v1.18.0.pdf"
doc = fitz.open(pdf_document)
output_word = r"D:\PycharmProjects\python_learning_record\national_computer_rank_examination\文件格式转换\机床通讯网关_通讯协议_v1.18.0.docx"

text = ""
# 遍历每一页并提取文本内容
for page_num in range(len(doc)):
    page = doc[page_num]
    text += page.get_text()

# 将提取的文本写入到Word文档中
with open(output_word, "w") as f:
    f.write(text)
